<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <div id="app">
        <div>{{msg}}</div>
        <input type="text" v-model="info">
        <button v-on:click="handlerClick">添加</button>
        <ul>
           <!-- <li v-for="item in list">{{item.text}}</li> -->
           <todo-item v-for="item in list" v-bind:item="item" v-bind:key="item.id"></todo-item>
        </ul>
    </div>
    <script>
        Vue.component('todo-item',{
            props:["item"],
            template:'<li>{{item.text}}</li>'
        })
       var app = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue',
                info: '',
                list: [],
            },
            methods: {
                handlerClick() {
                    var todo = {};
                    todo.id = Math.random();
                    todo.text = this.info;
                    this.list.push(todo);
                    this.info = '';
                    console.info(this.list)
                }
            }
        });

    </script>
</body>

</html>